using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// A Polygon is defined by an outer boundary and 0 or more inner boundaries. 
    /// The boundaries, in turn, are defined by LinearRings. When a Polygon is 
    /// extruded, its boundaries are connected to the ground to form additional 
    /// polygons, which gives the appearance of a building. 
    /// When a Polygon is extruded, each point is extruded individually. 
    /// Extruded Polygons use PolyStyle for their color, color mode, and fill. 
    /// </summary>
    public class KmlPolygon : KmlGeometry, IKmlElement, IKmlGeometry
    {
        private string tagName = "Polygon";

        #region OuterBoundaryIs

		private KmlLinearRing outerBoundaryIs = new KmlLinearRing();

        /// <summary>
        /// Gets or sets the outer boundary linear ring(s).
        /// </summary>
        /// <value>The outer boundary linear ring(s).</value>
        public KmlLinearRing OuterBoundaryIs
        {
          get { return outerBoundaryIs; }
          set { outerBoundaryIs = value; }
        } 
	
        #endregion               

        #region InnerBoundaryIs

		private List<KmlLinearRing> innerBoundaryIs = new List<KmlLinearRing>();

        /// <summary>
        /// Gets or sets the inner boundary linear ring(s).
        /// </summary>
        /// <value>The inner boundary linear ring(s).</value>
        public List<KmlLinearRing> InnerBoundaryIs
        {
          get { return innerBoundaryIs; }
          set { innerBoundaryIs = value; }
        } 
	
        #endregion               

        #region IKmlElement Members

        /// <summary>
        /// Name of the KML tag for this specific element.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        string IKmlElement.TagName
        {
            get { return tagName; }
        }

        #endregion

        #region IKmlGenerator Members

        /// <summary>
        /// Generates the KML for this element including its child elements.
        /// </summary>
        /// <param name="writer">The XML writer that will be used to generate the KML.</param>
        void IKmlGenerator.GenerateKml(System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartElement(tagName);
            base.GenerateKml(writer);
            writer.WriteStartElement("outerBoundaryIs");
            outerBoundaryIs.GenerateKml(writer);
            writer.WriteEndElement();

            if(innerBoundaryIs.Count>0)
            {
                writer.WriteStartElement("innerBoundaryIs");
                foreach(KmlLinearRing currentRing in innerBoundaryIs)
                    currentRing.GenerateKml(writer);
                writer.WriteEndElement();
            }

            
            
            writer.WriteFullEndElement();
        }

        #endregion
    
    }
}
